package javalearning.MultiThreads.news.day03;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class TimerDemo {
    public static void main(String[] args) {
        Timer timer = new Timer();
        TimerTask task = new TimerTask() {
            int i = 0;

            @Override
            public void run() {
                if (++i == 5) {
                    timer.cancel();
                    System.out.println("结束 ---" + new Date());
                }
                System.out.println("hahahaha " + i);
            }
        };
        timer.schedule(task, new Date(), 1000);
        System.out.println("开始 ---" + new Date());
    }
}
